package pkg.entity;

import com.google.appengine.api.datastore.Text;
import com.googlecode.objectify.Key;
import javax.persistence.Id;
import pkg.dao.EntityDAO;

public class Teacher extends ObjectifyEntity {

    @Id
    Long id;
    Key<Grade> gradeKey;
    Key<Prefix> prefixKey;
    String lastName;
    String picture;
    byte[] picBlob;
    Text text;
    boolean active;
    boolean biddable;
    boolean primary;

    public boolean isPrimary() {
        return primary;
    }

    public void setPrimary(boolean primary) {
        this.primary = primary;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public boolean isBiddable() {
        return biddable;
    }

    public void setBiddable(boolean biddable) {
        this.biddable = biddable;
    }

    public Key<Grade> getGradeKey() {
        return gradeKey;
    }

    public void setGradeKey(Key<Grade> gradeKey) {
        this.gradeKey = gradeKey;
    }

    public Long getGradeId() {
        return gradeKey.getId();
    }

    public void setGradeId(Long id) {
        gradeKey = new Key<Grade>(Grade.class, id);
    }

    public Grade getGrade() {
        Grade result = null;
        if (gradeKey != null) {
            EntityDAO dao = new EntityDAO();
            result = dao.find(gradeKey);
        }
        return result;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public Key<Prefix> getPrefixKey() {
        return prefixKey;
    }

    public void setPrefixKey(Key<Prefix> prefixKey) {
        this.prefixKey = prefixKey;
    }

    public Long getPrefixId() {
        return prefixKey.getId();
    }

    public void setPrefixId(Long id) {
        prefixKey = new Key<Prefix>(Prefix.class, id);
    }

    public String getText() {
        if (text != null) {
            return text.getValue();
        } else {
            return null;
        }
    }

    public void setText(String text) {
        this.text = new Text(text);
    }

    public byte[] getPicBlob() {
        return picBlob;
    }

    public void setPicBlob(byte[] picBlob) {
        this.picBlob = picBlob;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Teacher other = (Teacher) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public Key<ObjectifyEntity> getPrimaryKey() {
        return new Key(this.getClass(), id);
    }

    public String getFullName() {
        String result = "";
        if (prefixKey != null) {
            EntityDAO dao = new EntityDAO();
            Prefix p = dao.find(prefixKey);
            result = p.prefix + " ";
        }
        result = result + lastName;
        return result;
    }
}
